<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %>
<%@ page import="java.io.File" %>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %>
<%@ page import="org.apache.commons.fileupload.FileItem" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/6/14 0014
  Time: 15:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    DiskFileItemFactory dfif = new DiskFileItemFactory();
    dfif.setRepository(new File("e:/tmp"));
    dfif.setDefaultCharset("utf-8");
    ServletFileUpload upload = new ServletFileUpload(dfif);
    List<FileItem> fileItems = upload.parseRequest(request);
    for(FileItem fileItem:fileItems){
        if(fileItem.isFormField()){
            if(fileItem.getFieldName().equals("user")){
                String user = fileItem.getString("utf-8");
                out.print(user);
            }
        }else{
            fileItem.write(new File(application.getRealPath("/upload")+"abc.png"));

        }

    }

%>